package com.wanghlme.day26.web;

import com.wanghlme.day26.service.IEmpService;
import com.wanghlme.day26.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/toDel")
public class ToDelAction extends HttpServlet {
    private IEmpService empService;

    public ToDelAction() {
        empService = new EmpServiceImpl();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        System.out.println(id);
        int result = empService.delEmp(Integer.parseInt(id));
        System.out.println(result);
        resp.sendRedirect(req.getContextPath() + "/");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
